package com.ita.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ita.pojo.Customer;
import com.ita.service.CustomerService;

@Controller
public class CustomerController {

	@Autowired(required=true)
	private CustomerService cService;

	@RequestMapping(value = "/regist", method = RequestMethod.POST)
	public String regist(String name, String pwd, int age) {

		Customer c = new Customer();
		c.setAge(age);
		c.setPassword(pwd);
		c.setUname(name);
		if (cService.regist(c) == 1)
			return "login";
		else
			return "regist";
	
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String login(String name, String pwd) {

		if(("").equals(name)||("").equals(pwd))
			return "login";
		if (cService.login(name, pwd) == 1)
			return "success";
		else
			return "login";

	}

}
